package com.apiauto.data_util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.LinkedHashMap;
import java.util.Map;

import org.yaml.snakeyaml.Yaml;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.apiauto.log.Log;

public class YamlUtil {
	//yaml文件路径
	public String yamlPath;
	//初始化yaml路径
	public YamlUtil(String yamlPath) {
		this.yamlPath = yamlPath;
	}
	/**
	 * PS:获取yaml数据
	 * @return
	 */
	public Map<String,Map> getYamlData() {
		File file = new File(yamlPath);
		Yaml yaml = new Yaml();
		Map<String,Map> map = null;
		try {
			map = yaml.loadAs(new FileInputStream(file), Map.class);
		} catch (FileNotFoundException e) {
			Log.error("["+yamlPath+"]yaml文件读取异常");
		}
		return map;
	}
	public static void main(String[] args) {
		YamlUtil util = new YamlUtil("src/main/resources/case_yaml/test_case.yaml");
		Map<String,Map> map = util.getYamlData();
		Map<String,Map> map1 = map.get("test2");
		Map<String,Map> map2 = map1.get("requestBody");
		String a = JSONObject.toJSONString(map2).toString();
		System.out.println(a);
	}
}
